/***************************************************************************
 * The Open Armory API is a project to retrieve World of Warcraft(R) 
 * related XML data from The Armory.
 * 
 * The data retrieved via the Open Armory API from The Armory is 
 * proprietary to Blizzard Entertainment, Inc(R).
 * *************************************************************************
 * Copyright (C) 2009 - 2010 Tedla M.B. Brandsema
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************************/
package net.openarmory.core.domain.url;

import java.net.MalformedURLException;
import java.net.URL;

import net.openarmory.core.domain.constants.ArmoryCharacterDataType;
import net.openarmory.core.domain.constants.ArmoryZone;

import org.apache.log4j.Logger;

// TODO: Auto-generated Javadoc
/**
 * The Class ArmoryCharacterUrlBuilder.
 */
public final class ArmoryCharacterUrlBuilder extends ArmoryUrlBuilder {

	/** The log. */
	private static final Logger LOG = Logger
			.getLogger(ArmoryCharacterUrlBuilder.class);

	/** The zone. */
	private ArmoryZone zone;

	/** The realm. */
	private String realm;

	/** The character name. */
	private String characterName;

	/** The armory character data type. */
	private ArmoryCharacterDataType armoryCharacterDataType;

	/**
	 * Gets the zone.
	 * 
	 * @return the zone
	 */
	public ArmoryZone getZone() {
		return this.zone;
	}

	/**
	 * Gets the realm.
	 * 
	 * @return the realm
	 */
	public String getRealm() {
		return this.realm;
	}

	/**
	 * Gets the character name.
	 * 
	 * @return the character name
	 */
	public String getCharacterName() {
		return this.characterName;
	}

	/**
	 * Gets the armory data type.
	 * 
	 * @return the armory data type
	 */
	public ArmoryCharacterDataType getArmoryDataType() {
		return this.armoryCharacterDataType;
	}

	/**
	 * Gets the armory character url.
	 * 
	 * @param zone
	 *            the zone
	 * @param realm
	 *            the realm
	 * @param characterName
	 *            the character name
	 * @param armoryCharacterDataType
	 *            the armory character data type
	 * @return the armory character url
	 */
	public ArmoryCharacterUrl getArmoryCharacterUrl(final ArmoryZone zone,
			final String realm, final String characterName,
			final ArmoryCharacterDataType armoryCharacterDataType) {
		final ArmoryCharacterUrl armoryCharacterUrl = new ArmoryCharacterUrl();
		this.zone = zone;
		this.realm = realm;
		this.characterName = characterName;
		this.armoryCharacterDataType = armoryCharacterDataType;

		try {
			armoryCharacterUrl.setUrl(new URL(zone.getUrlConfigProperty()
					+ armoryCharacterDataType.getUrlConfigProperty()
					+ ArmoryUrlBuilder.QUERY_STRING_SEPERATOR
					+ ArmoryUrlBuilder.REALM_URL_VARIABLE + urlEncode(realm)
					+ ArmoryUrlBuilder.QUERY_VARIABLE_SEPERATOR
					+ ArmoryUrlBuilder.CHARACTER_NAME_URL_VARIABLE
					+ urlEncode(characterName)));
		} catch (final MalformedURLException e) {
			LOG.fatal("Malformed character url", e);
		}
		return armoryCharacterUrl;
	}

}
